package com.finer.service.impl;

import com.finer.entity.document.FinerSupplies;
import com.finer.dao.FinerSuppliesDao;
import com.finer.service.FinerSuppliesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 供应商表(FinerSupplies)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:41
 */
@Service("finerSuppliesService")
public class FinerSuppliesServiceImpl implements FinerSuppliesService {
    @Resource
    private FinerSuppliesDao finerSuppliesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerSupplies queryById(Integer id) {
        return this.finerSuppliesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerSupplies 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSupplies> queryByPage(FinerSupplies finerSupplies, PageRequest pageRequest) {
        long total = this.finerSuppliesDao.count(finerSupplies);
        return new PageImpl<>(this.finerSuppliesDao.queryAllByLimit(finerSupplies, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSupplies 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSupplies insert(FinerSupplies finerSupplies) {
        this.finerSuppliesDao.insert(finerSupplies);
        return finerSupplies;
    }

    /**
     * 修改数据
     *
     * @param finerSupplies 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSupplies update(FinerSupplies finerSupplies) {
        this.finerSuppliesDao.update(finerSupplies);
        return this.queryById(finerSupplies.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerSuppliesDao.deleteById(id) > 0;
    }
}
